function [Q,R] = restoring_divider(N,D)
    % N < D
    % Q = N/D
    % N = Numerator (dividend)
    % D = Denominator (divisor) 
    
    len_n = length(N);
    n = len_n*2-1;
    Q = zeros(1, len_n);
    R = [zeros(1,len_n) N]; % R = N
    D = [zeros(1,len_n) D]; 
    for i = n:-1:1,
        R = [R(2:end) 0]; % R << 1
        [R, co] = add_sub(R,D,1); % R = R - D
        if(co)
            Q(n-i+1) = 1;
        else  % 2R-D < 0
            Q(n-i+1) = 0;
            [R, t] = add_sub(R,D,0); % restore, R = 2R
        end
    end
end
